package chars;

import java.io.CharArrayReader;
import java.io.IOException;
import java.io.PushbackReader;

/**
 * @Description
 * @Author zhaobaolin
 * @Date 2018/11/11
 */
public class PushbackReaderExample {
    public static void main(String[] args) {
        demo();
    }
    private static void demo()
    {
        String source = "12345";
        char[] c = source.toCharArray();
        CharArrayReader charArrayReader = new CharArrayReader(c);
        PushbackReader push = new PushbackReader(charArrayReader);
        int bytes;
        try{
            int size = source.length();
            for(int i=0;i<size;i++){
                bytes = push.read();
                if(i == 1){
                    push.unread(bytes);
                }
                if(i == 3){
                    push.unread(bytes);
                }
                System.out.print((char) bytes);
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
